<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="考勤日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="attendanceDate">
              <j-date placeholder="请选择考勤日期" v-model="model.attendanceDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="部门编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deptCode">
              <a-input v-model="model.deptCode" placeholder="请输入部门编码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="员工类别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="postName">
              <a-input v-model="model.firstLevelDept" placeholder="请输入员工类别"  ></a-input>
            </a-form-model-item>
          </a-col>

          <a-col :span="24">
            <a-form-model-item label="二级部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="secondLevelDept">
              <a-input v-model="model.secondLevelDept" placeholder="请输入二级部门"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="三级部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="thirdLevelDept">
              <a-input v-model="model.thirdLevelDept" placeholder="请输入三级部门"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="四级部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fourthLevelDept">
              <a-input v-model="model.fourthLevelDept" placeholder="请输入四级部门"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="五级部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fifthLevelDept">
              <a-input v-model="model.fifthLevelDept" placeholder="请输入五级部门"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="部门名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deptName">
              <a-input v-model="model.deptName" placeholder="请输入部门名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="出勤人数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="attendanceCount">
              <a-input v-model="model.attendanceCount" placeholder="请输入出勤人数"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="请假人数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="leaveCount">
              <a-input v-model="model.leaveCount" placeholder="请输入请假人数"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="在职人数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="activeEmployees">
              <a-input v-model="model.activeEmployees" placeholder="请输入在职人数"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="离职人数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="terminationCount">
              <a-input v-model="model.terminationCount" placeholder="请输入离职人数"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="入职人数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="onboardingCount">
              <a-input v-model="model.onboardingCount" placeholder="请输入入职人数"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'AttendanceEmploymentReportForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/ch/attendanceEmploymentReport/add",
          edit: "/ch/attendanceEmploymentReport/edit",
          queryById: "/ch/attendanceEmploymentReport/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>